from django.db import models
from Administrative_office_system.utils.BaseModel import BaseModel
from DjangoUeditor.models import UEditorField

# Create your models here.


class Category(BaseModel):
    name = models.CharField(max_length=255, verbose_name='名称')


class Article(BaseModel):
    """文章"""
    TYPE = (('app', 'app'),
            ('pc', 'pc'))
    author = models.ForeignKey(
        'personal_center.User',
        verbose_name="作者",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    title = models.CharField(max_length=255, verbose_name='标题')
    content_html = UEditorField(verbose_name="文章内容html", default='', width=1000, height=300, imagePath='app/images/',
                                filePath='app/files/')
    content_text = models.TextField(verbose_name="文章内容")
    like_users = models.ManyToManyField('personal_center.User', verbose_name='点赞人员',
                                        related_name='article_like_users', blank=True)
    collection_users = models.ManyToManyField('personal_center.User', verbose_name='收藏人员',
                                              related_name='article_collection_users', blank=True)
    see_users = models.ManyToManyField('personal_center.User', verbose_name='查看人员',
                                       related_name='article_see_users', blank=True)
    is_draft = models.BooleanField(default=False, verbose_name='是否草稿')
    is_delete = models.BooleanField(default=False, verbose_name='是否删除')
    category = models.ForeignKey(
        'Category',
        verbose_name="分类",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    type = models.CharField('来源', max_length=10, choices=TYPE, default='pc')


class ArticleComment(BaseModel):
    comment_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="评论人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    respondent = models.ForeignKey(
        'personal_center.User',
        verbose_name="被回复人",
        blank=False,
        null=False,
        related_name='respondent_users',
        on_delete=models.CASCADE)
    article = models.ForeignKey(
        'Article',
        verbose_name="文章",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    parent_id = models.ForeignKey(
        'self',
        verbose_name="父评论",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    comment_text = models.TextField(verbose_name="评论内容")
